package com.eqdd.yiqidian.ui.gongneng.renshi.yuangongdangan.ruzhuyaoqing;

import android.databinding.DataBindingUtil;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.BumenListActivityCustom;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.InviteCareerListResultBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.gongneng.renshi.zuzhiguanli.InvitePersonToComActivity;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class SelectPostFromComActivity extends BaseActivity {
    private BumenListActivityCustom dataBinding;
    private SlimAdapterEx<InviteCareerListResultBean> slimAdapterEx;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_bumen_list);
        initTopTitleBar(View.VISIBLE, "岗位列表");
    }

    @Override
    public void initData() {
        if (slimAdapterEx == null) {
            dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
            slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_06, new SlimInjector<InviteCareerListResultBean>() {
                @Override
                public void onInject(InviteCareerListResultBean data, IViewInjector injector) {
                    injector.text(R.id.tv_upper_content, data.getName())
                            .text(R.id.tv_down_content, data.getDename());
                }
            }).attachTo(dataBinding.recyclerView).updateData(new ArrayList());
            ItemClickSupport.addTo(dataBinding.recyclerView).setOnItemClickListener((rv, position, v) -> {
                InviteCareerListResultBean dataItem = slimAdapterEx.getDataItem(position);
                Bundle bundle = new Bundle();
                bundle.putString(Config.DEPARTMENT_NAME, dataItem.getDename());
                bundle.putString(Config.DEPARTMENT_ID, dataItem.getDeid() + "");
                bundle.putString(Config.CAREER_ID, dataItem.getId() + "");
                bundle.putString(Config.CAREER_NAME, dataItem.getName());
                startActivity(InvitePersonToComActivity.class, bundle);
            });
        }
    }

    @Override
    public void setView() {
        OkGo.<HttpResult<List<InviteCareerListResultBean>>>post(HttpConfig.BASE_URL + HttpConfig.SELECT_CAREER_ALL)
                .params("comid", user.getCompanyId())
                .params("userGuid", user.getGuid())
                .execute(new DialogCallBack<HttpResult<List<InviteCareerListResultBean>>>(this) {

                    @Override
                    public void onSuccess(Response<HttpResult<List<InviteCareerListResultBean>>> response) {
                        HttpResult<List<InviteCareerListResultBean>> httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                            ToastUtil.showShort(httpResult.getMsg());
                            slimAdapterEx.updateData(httpResult.getItems());
                        }
                    }
                });

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
